Regexp

Hi All,
Ok, another dumb question.
When using REGEXP, does it only return TRUE or FALSE?
Here is my example:
{code} const Regexp UL_PARSE_PHONE = regexp2 "^2-90-80-9http://-\\. 2-90-90-9http://-\\. 0-90-90-90-9$"

if (UL_PARSE_PHONE phone)
{
print "*US*\n"

return propertyValue // phone number is in US Format
}
else {
print "*NON-US*\n"
}
{Code}

Can't I use REGEXP to strip?
For example if I have this phone string "616-555-1212 " <-- notice 2 spaces
Is there a certain way with REGEXP to strip off the end spaces?
Or does it just do matching?
I am still trying to get a hold on this.
I did however get the above to work how I wanted perse.
Thanks.
Jerry
SystemAdmin - Fri Aug 05 10:07:32 EDT 2011

Re: Regexp
llandale - Fri Aug 05 13:15:38 EDT 2011

Regular expression comparisons (and the "matches" command) only return booleans. But if succesful you can build the part of the string using the match x substring command. Since your Regexp has the end-of-string indicator '$' at the end, it won't ignore trailing white space and will fail. If you remove the '$' then anything after the other part of the regexp will be ignored, and it WILL match. You can then get the part that matches using:

phonematch 0

In my other post you could add
... print in_RawPhonematch 1 "\t" in_RawPhonematch 2 "\t" in_RawPhonematch 3 "\n"
to see how the paranthesis in the expression correspond to the matching ordinals; noticing that my first set of parens corresponds to match 1 etc.

You have to play with it for a while to get used to it.

  • Louie

Re: Regexp
llandale - Fri Aug 05 13:18:01 EDT 2011

llandale - Fri Aug 05 13:15:38 EDT 2011
Regular expression comparisons (and the "matches" command) only return booleans. But if succesful you can build the part of the string using the match x substring command. Since your Regexp has the end-of-string indicator '$' at the end, it won't ignore trailing white space and will fail. If you remove the '$' then anything after the other part of the regexp will be ignored, and it WILL match. You can then get the part that matches using:

phonematch 0

In my other post you could add
... print in_RawPhonematch 1 "\t" in_RawPhonematch 2 "\t" in_RawPhonematch 3 "\n"
to see how the paranthesis in the expression correspond to the matching ordinals; noticing that my first set of parens corresponds to match 1 etc.

You have to play with it for a while to get used to it.

  • Louie

Did someone say "Preview" lol

Regular expression comparisons (and the "matches" command) only return booleans. But if succesful you can build the part of the string using the [match x] substring command. Since your Regexp has the end-of-string indicator '$' at the end, it won't ignore trailing white space and will fail. If you remove the '$' then anything after the other part of the regexp will be ignored, and it WILL match. You can then get the part that matches using:

phone[match 0]

In my other post you could add
... print in_RawPhone[match 1] "\t" in_RawPhone[match 2] "\t" in_RawPhone[match 3] "\n"
to see how the paranthesis in the expression correspond to the matching ordinals; noticing that my first set of parens corresponds to match 1 etc.

You have to play with it for a while to get used to it.

Re: Regexp
SystemAdmin - Fri Aug 05 15:07:29 EDT 2011

llandale - Fri Aug 05 13:18:01 EDT 2011
Did someone say "Preview" lol

Regular expression comparisons (and the "matches" command) only return booleans. But if succesful you can build the part of the string using the [match x] substring command. Since your Regexp has the end-of-string indicator '$' at the end, it won't ignore trailing white space and will fail. If you remove the '$' then anything after the other part of the regexp will be ignored, and it WILL match. You can then get the part that matches using:

phone[match 0]

In my other post you could add
... print in_RawPhone[match 1] "\t" in_RawPhone[match 2] "\t" in_RawPhone[match 3] "\n"
to see how the paranthesis in the expression correspond to the matching ordinals; noticing that my first set of parens corresponds to match 1 etc.

You have to play with it for a while to get used to it.

Hi Louie,
That is what I thought. I was hoping otherwise, but oh well.
The match part I have not mastered yet.
I tried using what you gave me and all I got abck was TRUE or FALSE.
I am not sure waht I was doing wrong, but I was able to do it another way.
Thanks for the reply though!
Jerry

Re: Regexp
llandale - Sun Aug 07 13:30:21 EDT 2011

SystemAdmin - Fri Aug 05 15:07:29 EDT 2011
Hi Louie,
That is what I thought. I was hoping otherwise, but oh well.
The match part I have not mastered yet.
I tried using what you gave me and all I got abck was TRUE or FALSE.
I am not sure waht I was doing wrong, but I was able to do it another way.
Thanks for the reply though!
Jerry

These two are basically the same:
... if (matches(string Expression, Target))
... if ((regexp2(Expression)) Target))
matches works on simple Expressions like "shall"; I don't know if it works on the more complicated ones that regexp2 does. Since the matches and the regexp2 commands are EXTREMELY slow, for programs that to 10s of 1000s of matches you should define regexp2 outside the function and do it once.

Perhaps you confuse the "matches(string, string)" command with the "match int" range expression.

The "match int" range is used after one of the above two proves successful. You can extract the parts of the Target that correspond to the individual parts of the Expression. match 0 matches the entire part of Target that qualifies for Expression. match 1 through match 9 match that part of Target that correspond to the individual parts of Expression enclosed in Parens.

Regexp re = regexp2("(e1)o1(e2)o2(e3(e4))")
if (re Target)
then Target[match 1] == e1
     Target[match 2] == e2
     Target[match 3] == e3
     Target[match 4] == e4


match 10 is illegal, only 0-9 are allowed.
Note that since o1 and o2 are not within parenthesis, they will be included only in match 0 not any of the others.

It helps to print "Targetmatch 1" etc when debugging, then you know for sure which parts match the match i.

 

 

  • Louie